public abstract class Message {

    TIMMessage message;
    private boolean hasTime;
    private String desc;

    public TIMMessage getMessage() {
        return message;
    }

    //展示消息_需要重写
    public abstract void showMessage(ChatAdapter.ViewHolder viewHolder, Context context);

    //返回聊天气泡样式
    public RelativeLayout getBubbleView(ChatAdapter.ViewHolder viewHolder, boolean bushi_hongbao, final Context context){

        viewHolder.systemMessage.setVisibility(hasTime?View.VISIBLE:View.GONE);
        viewHolder.systemMessage.setText(TimeUtil.getChatTimeStr(message.timestamp()));
        showDesc(viewHolder);

        if(bushi_hongbao){
            viewHolder.hb.setVisibility(View.GONE);
            if (message.isSelf()){
                viewHolder.leftPanel.setVisibility(View.GONE);
                viewHolder.rightPanel.setVisibility(View.VISIBLE);
                Glide.with(context).load(MyApplication.getInstance().getMetouxiang()+ImageUtil.URL_CUT).into(viewHolder.rightpic);
                return viewHolder.rightMessage;
            }else{
                viewHolder.leftPanel.setVisibility(View.VISIBLE);
                viewHolder.rightPanel.setVisibility(View.GONE);
                if(message.getConversation().getType()!=TIMConversationType.Group){
                    Glide.with(context).load(MyApplication.getInstance().getTouxiang()+ImageUtil.URL_CUT).into(viewHolder.leftpic);
                }else {
                    String face=MyApplication.getInstance().getP().getString(message.getSender(),ImageUtil.URL_DEFAUT);
                    Glide.with(context).load(face+ImageUtil.URL_CUT).into(viewHolder.leftpic);
                }
                viewHolder.sender.setVisibility(View.GONE);
                viewHolder.leftpic.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent=new Intent(context, ProfileActivity.class);
                        intent.putExtra("identify",message.getSender());
                        context.startActivity(intent);
                    }
                });
                return viewHolder.leftMessage;
            }
        }else {
            viewHolder.leftPanel.setVisibility(View.GONE);
            viewHolder.rightPanel.setVisibility(View.GONE);
            viewHolder.hb.setVisibility(View.VISIBLE);
            if(message.isSelf()){
                viewHolder.hb_name.setText("你领取了"+MyApplication.getInstance().getNow_name()+"的");
            }else {
                viewHolder.hb_name.setText(MyApplication.getInstance().getNow_name()+"领取了你的");
            }
            return viewHolder.hb;
        }
    }


    public void showStatus(ChatAdapter.ViewHolder viewHolder){
        
    }

    //自己发的消息
    public boolean isSelf(){
        return message.isSelf();
    }

    //获取摘要
    public abstract String getSummary();

    String getRevokeSummary() {
        if (message.status() == TIMMessageStatus.HasRevoked) {
            return getSender() + "撤回了一条消息";
        }
        return null;
    }

    public abstract void save();

    public void remove(){
        TIMMessageExt ext = new TIMMessageExt(message);
        ext.remove();
    }

    public boolean getHasTime() {
        return hasTime;
    }

    public void setHasTime(TIMMessage message){
        if (message == null){
            hasTime = true;
            return;
        }
        hasTime = this.message.timestamp() - message.timestamp() > 300;
    }

    public boolean isSendFail(){
        return message.status() == TIMMessageStatus.SendFail;
    }

    protected void clearView(ChatAdapter.ViewHolder viewHolder,boolean bushi_hongbao,Context context){
        viewHolder.lv.setText("");
        viewHolder.rv.setText("");
        getBubbleView(viewHolder,bushi_hongbao,context).removeAllViews();
        getBubbleView(viewHolder,bushi_hongbao,context).setOnClickListener(null);

    }

    boolean checkRevoke(ChatAdapter.ViewHolder viewHolder) {
        if (message.status() == TIMMessageStatus.HasRevoked) {
            viewHolder.leftPanel.setVisibility(View.GONE);
            viewHolder.rightPanel.setVisibility(View.GONE);
            viewHolder.systemMessage.setVisibility(View.VISIBLE);
            viewHolder.systemMessage.setText(getSummary());
            return true;
        }
        return false;
    }

    public String getSender(){
        if (message.getSender() == null) return "";
        return message.getSender();
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    private void showDesc(ChatAdapter.ViewHolder viewHolder){
        if (desc == null || desc.equals("")){
            viewHolder.rightDesc.setVisibility(View.GONE);
        }else{
            viewHolder.rightDesc.setVisibility(View.VISIBLE);
            viewHolder.rightDesc.setText(desc);
        }
    }



}
